package com.xlh.controller.conclude;

import cn.hutool.core.util.StrUtil;
import com.xlh.common.Result;
import com.xlh.dto.conclude.ConcludeDTO;
import com.xlh.dto.conclude.ConcludeParamDTO;
import com.xlh.dto.conclude.ConcludeUpPublicDTO;
import com.xlh.param.conclude.ConcludeAddParam;
import com.xlh.param.conclude.ConcludeCopyParam;
import com.xlh.param.conclude.ConcludeUpdateParam;
import com.xlh.service.conclude.ConcludeService;
import com.xlh.vo.conclude.ConcludeDetailsVO;
import com.xlh.vo.conclude.ConcludeListInfoVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 工程认证 - 课程达成度
 * <p>
 * chufangzheng
 */
@Api(tags = "ConcludeController", description = "工程认证 - 达程度")
@RestController
@RequestMapping("/conclude/conclude")
public class ConcludeController {

    @Autowired
    private ConcludeService concludeService;

    @ApiOperation("达成度显示列表")
    @GetMapping("/list")
    @PreAuthorize("@permissionValidator.isTeacher()")
    public Result<List<ConcludeListInfoVO>> list(@RequestParam("courseId") Long courseId) {
        List<ConcludeListInfoVO> list = concludeService.list(courseId);
        return Result.success(list);
    }

    @ApiOperation("达成度添加")
    @PostMapping("/add")
    @PreAuthorize("@permissionValidator.isTeacher()")
    public Result<String> add(@Valid @RequestBody ConcludeAddParam concludeAddParam) {
        concludeService.add(concludeAddParam);
        return Result.success();
    }

    @ApiOperation("达成度拷贝")
    @PostMapping("/copy")
    @PreAuthorize("@permissionValidator.isTeacher()")
    public Result<String> copy(@Valid @RequestBody ConcludeCopyParam concludeCopyParam) {
        concludeService.copy(concludeCopyParam);
        return Result.success();
    }


    @ApiOperation("课程达成度更新当前达成度")
    @GetMapping("/exeupdate")
    @PreAuthorize("@permissionValidator.isTeacher()")
    public Result<String> exeUpdate(Long concludeId) {

        concludeService.exeUpdate(concludeId);
        return Result.success();
    }


    @ApiOperation("达成度修改")
    @PostMapping("/update")
    @PreAuthorize("@permissionValidator.isTeacher()")
    public Result update(@Valid @RequestBody ConcludeUpdateParam concludeUpdateParam){
        concludeService.update(concludeUpdateParam);
        return Result.success();
    }


    @ApiOperation("是否公布状态修改")
    @PostMapping("/ispublic")
    @PreAuthorize("@permissionValidator.isTeacher()")
    public Result<String> ispublic(@Valid @RequestBody ConcludeUpPublicDTO ispublic) {
        concludeService.ispublic(ispublic);
        return Result.success();
    }


    @ApiOperation("达成度删除")
    @DeleteMapping("/delete")
    @PreAuthorize("@permissionValidator.isTeacher()")
    public Result<String> delete(@Valid @RequestBody ConcludeParamDTO paramDTO) {
        String message = concludeService.delete(paramDTO.getId());
        if(StrUtil.isNotBlank(message)){
            return Result.error(message);
        }
        return Result.success();
    }

    @ApiOperation("课程达成度详情")
    @GetMapping("/details")
    @PreAuthorize("@permissionValidator.isTeacher()")
    public Result<ConcludeDetailsVO> details(Long id) {

        return Result.success(concludeService.details(id));
    }


}
